<template>
    <div class="container">
      <!-- <div class="btnList">
        <el-date-picker
          v-model="erpCenter.date"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
        ></el-date-picker>
        <el-button
          size="small"
          type="success"
          class="handleSearch"
          icon="el-icon-check"
          @click="pull()"
          >拉取ERP</el-button
        >
      </div> -->
  
      <div class="top">
        <el-input
          style="width: 200px; margin-bottom: 5px"
          v-model="search.code"
          placeholder="请输入订单编码"
          clearable
        ></el-input>
        <el-input
          style="width: 300px"
          :disabled="true"
          placeholder="请搜索机构信息"
          v-model="organizationList.name"
        >
          <template slot="prepend"
            >机构</template
          >
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="organizationBtn"
          ></el-button>
        </el-input>
        <el-input
          style="width: 300px"
          :disabled="true"
          placeholder="请搜索类别信息"
          v-model="classNameList.name"
        >
          <template slot="prepend"
            >类别</template
          >
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="classBtn"
          ></el-button>
        </el-input>
        <el-input
          style="width: 300px"
          :disabled="true"
          placeholder="请搜索仓库"
          v-model="warehouseList.name"
        >
          <template slot="prepend"
            >仓库</template
          >
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="warehouseBtn"
          ></el-button>
        </el-input>
        <el-select v-model="search.order_status" placeholder="请选择状态">
          <el-option
            v-for="item in option"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-select v-model="search.type" placeholder="请选择订单类型">
          <el-option
            v-for="item in type"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-select v-model="search.otype" placeholder="请选择订单商品类型">
          <el-option
            v-for="item in otype"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-select
          v-model="search.hangcai_flag"
          @change="hangcai_flagChe"
          placeholder="请选择订单行采类型"
        >
          <el-option
            v-for="item in hangcai_flagList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-date-picker
          value-format="yyyy-MM-dd"
          v-model="date"
          type="daterange"
          :clearable="false"
          range-separator="至"
          start-placeholder="下单开始日期"
          end-placeholder="下单结束日期"
        ></el-date-picker>
        <el-date-picker
          value-format="yyyy-MM-dd"
          v-model="d_date"
          type="daterange"
          :clearable="false"
          range-separator="至"
          start-placeholder="发货开始日期"
          end-placeholder="发货结束日期"
        ></el-date-picker>
        <el-button
          size="small"
          type="primary"
          class="handleSearch"
          icon="el-icon-search"
          @click="handleSearch()"
          >查询</el-button
        >
        <el-button
          size="small"
          type="danger"
          class="handleSearch"
          icon="el-icon-delete"
          @click="empty()"
          >清空</el-button
        >
        <el-button
          type="info"
          size="small"
          icon="el-icon-tickets"
          @click="derive(0)"
          >订单商品列表导出xlsx</el-button
        >
        <el-button
          type="info"
          size="small"
          icon="el-icon-tickets"
          @click="derive(1)"
          >订单商品列表导出</el-button
        >
        <el-button
          type="info"
          size="small"
          icon="el-icon-tickets"
          @click="derive(2)"
          >门店下单商品</el-button
        >
        <el-button
          type="info"
          size="small"
          icon="el-icon-tickets"
          @click="derive(3)"
          >下单商品汇总</el-button
        >
        <el-button
          type="info"
          size="small"
          icon="el-icon-tickets"
          @click="deriveList()"
          >门店要货汇总导出</el-button
        >
        <el-button
          size="small"
          type="primary"
          class="handleSearch"
          icon="el-icon-edit"
          @click="addGoods()"
          >订单添加</el-button
        >
  
        <el-button
          size="small"
          type="primary"
          class="handleSearch"
          icon="el-icon-edit"
          @click="addHcGoods()"
          >行采订单添加</el-button
        >
        <el-button
          size="small"
          type="primary"
          class="handleSearch"
          icon="el-icon-edit"
          @click="addMoreGoods()"
          >单品多店发货</el-button
        >
        <el-button
          v-if="hangcai_flagType"
          size="small"
          type="primary"
          class="handleSearch"
          icon="el-icon-edit"
          @click="completeList()"
          >批量发货</el-button
        >
      </div>
      <el-table
        max-height="600"
        :data="tableData"
        border
        style="width: 100%"
        empty-text="暂无数据"
        ref="multipleTable"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="50"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="serial_code"
          label="订单号"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="order_code"
          label="erp订单号"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="statusMsg"
          label="订单状态"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="typeMsg"
          label="订单类型"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="otypeMsg"
          label="订单商品类型"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="erp_org_code"
          label="门店编码"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="org_name"
          label="门店名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="org_address"
          label="门店地址"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="created_at"
          label="下单时间"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="delivery_at"
          label="发货时间"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="finish_at"
          label="收货时间"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="warehouse_name"
          label="仓库名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="dev_desc"
          label="是否可发货"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="description"
          label="备注"
          align="center"
        ></el-table-column>
        <el-table-column label="操作" width="300" align="center">
          <template slot-scope="scope">
            <el-button
              type="info"
              size="mini"
              icon="el-icon-info"
              @click="handleEdit(scope)"
              >详情</el-button
            >
            <el-button
              type="info"
              size="mini"
              icon="el-icon-info"
              @click="handleinfo(scope)"
              >审核详情</el-button
            >
            <el-button
              type="primary"
              size="mini"
              v-if="scope.row.order_status == 0 && acc_type != 6"
              icon="el-icon-edit"
              @click="modification(scope)"
              >编辑</el-button
            >
            <!-- <el-button
              v-if="scope.row.order_status == 0 && acc_type != 6"
              type="primary"
              size="mini"
              icon="el-icon-refresh"
              @click="synchronization(scope)"
              >同步库存并发货</el-button
            > -->
            <el-button
              type="success"
              size="mini"
              v-if="scope.row.order_status == 0 && acc_type != 6"
              icon="el-icon-circle-check"
              @click="complete(scope)"
              >确认发货</el-button
            >
            <el-button
              size="mini"
              v-if="scope.row.order_status == 0"
              type="danger"
              icon="el-icon-delete"
              @click="handleDelete(scope)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
        center
        title="商超订单列表导出"
        :visible.sync="buttomDialog.centerDialogVisible"
        width="30%"
      >
        <div class="btnList">
          <el-button type="primary" @click="deriveBtn(1)">全部导出</el-button>
          <el-button type="primary" @click="deriveBtn(2)">中仓导出</el-button>
          <el-button type="primary" @click="deriveBtn(3)">供应商导出</el-button>
        </div>
      </el-dialog>
      <!-- 分页 -->
      <pagination
        @page="handleSizeChange"
        @pagesize="handleCurrentChange"
        :pageData="pageData"
      ></pagination>
      <orderModificationDialog
        :detailsDialog="detailsDialog"
        @upData="getData"
      ></orderModificationDialog>
      <compileHcgoodDialog
        :detailsDialog="detailsHcDialog"
        @upData="getData"
      ></compileHcgoodDialog>
      <organizationDialog
        :organizatioDialog="organizatioDialog"
        @tag="supplierTag"
      ></organizationDialog>
      <particularsDialog
        :particularsDialogs="particularsDialogs"
      ></particularsDialog>
      <particularsHcDialog
        :particularsDialogs="particularsHcDialogs"
      ></particularsHcDialog>
      <supercherkinfoDialog
        :supercherkinfoDialogs="supercherkinfoDialogs"
      ></supercherkinfoDialog>
      <addHcGoodDialog
        :addDialog="addHcDialog"
        @upData="getData"
      ></addHcGoodDialog>
      <warehouseselect
        :warehouseselect="warehouseselect"
        @tag="warehouseTag"
      ></warehouseselect>
      <addMoreGoodDialog
        :addDialog="addMoreDialog"
        @upData="getData"
      ></addMoreGoodDialog>
      <addGoodDialog :addDialog="addDialog" @upData="getData"></addGoodDialog>
      <classDialog :classdialog="classdialog" @tag="classTag"></classDialog>
    </div>
  </template>
  <script>
  import { getToken } from "@/utils/auth";
  import Pagination from "@/components/pagination";
  import {
    selectOrderList,
    confirmOrder,
    pullOrderData,
    synchroStockByOld,
    confirmHangCaiOrder,
    deleteOrder,
    getSourceData
  } from "@/api/superOrderNew/superOrderList";
  import AddMoreGoodDialog from "@/components/superOrderNew/addMoreGoodDialog";
  import AddGoodDialog from "@/components/superOrderNew/addGoodDialog";
  import AddHcGoodDialog from "@/components/superOrderNew/addHcGoodDialog";
  import CompileHcgoodDialog from "@/components/superOrderNew/compileHcgoodDialog";
  import OrderModificationDialog from "@/components/superOrderNew/orderModificationDialog";
  import OrganizationDialog from "@/components/superGrossMargin/organizationDialog";
  import ParticularsDialog from "@/components/superOrderNew/particularsDialog";
  import ParticularsHcDialog from "@/components/superOrderNew/particularsHcDialog";
  import SupercherkinfoDialog from "@/components/superOrderNew/supercherkinfoDialog";
  import ClassDialog from "@/components/superGrossMargin/classDialog";
  import Warehouseselect from "@/components/commodity/warehouseselect";
  export default {
    components: {
      pagination: Pagination,
      orderModificationDialog: OrderModificationDialog,
      organizationDialog: OrganizationDialog,
      particularsDialog: ParticularsDialog,
      particularsHcDialog: ParticularsHcDialog,
      supercherkinfoDialog: SupercherkinfoDialog,
      addGoodDialog: AddGoodDialog,
      addHcGoodDialog: AddHcGoodDialog,
      addMoreGoodDialog: AddMoreGoodDialog,
      classDialog: ClassDialog,
      compileHcgoodDialog: CompileHcgoodDialog,
      warehouseselect: Warehouseselect
    },
    data() {
      return {
        //页面数据
        tableData: [],
        //分页
        pageData: {
          pageSizes: [10, 20],
          pageSize: 10,
          page: 1,
          total: null,
          layout: "total, sizes, prev, pager, next, jumper"
        },
        erpCenter: {
          date: ""
        },
        classNameList: {
          name: "",
          code: ""
        },
        search: {
          code: "",
          order_status: "",
          start_date: "",
          end_date: "",
          d_start_date: "",
          d_end_date: "",
          type: "",
          otype: "",
          hangcai_flag: ""
        },
        hangcai_flagType: false,
        warehouseselect: {
          centerDialogVisible: false
        },
        addDialog: {
          centerDialogVisible: false
        },
        addHcDialog: {
          centerDialogVisible: false
        },
        addMoreDialog: {
          centerDialogVisible: false
        },
        detailsDialog: {
          centerDialogVisible: false,
          id: "",
          erp_org_code: ""
        },
        detailsHcDialog: {
          centerDialogVisible: false,
          id: "",
          erp_org_code: ""
        },
        buttomDialog: {
          centerDialogVisible: false,
          sum: 0
        },
        organizatioDialog: {
          centerDialogVisible: false
        },
        particularsDialogs: {
          centerDialogVisible: false,
          id: ""
        },
        particularsHcDialogs: {
          centerDialogVisible: false,
          id: ""
        },
        supercherkinfoDialogs: {
          centerDialogVisible: false,
          id: ""
        },
        classdialog: {
          centerDialogVisible: false
        },
        organizationList: {
          name: "",
          code: ""
        },
        warehouseList: {
          name: "",
          code: ""
        },
        type: [
          {
            value: -1,
            label: "全部"
          },
          {
            value: 1,
            label: "商超订单"
          },
          {
            value: 2,
            label: "ERP商超订单"
          },
          {
            value: 3,
            label: "中仓强配订单"
          },
          {
            value: 13,
            label: "中仓回退订单"
          }
        ],
        hangcai_flagList: [
          {
            value: -1,
            label: "全部"
          },
          {
            value: 0,
            label: "非行采"
          },
          {
            value: 1,
            label: "行采"
          }
        ],
        otype: [
          // {
          //   value: -1,
          //   label: "全部",
          // },
          // {
          //   value: 1,
          //   label: "粮油",
          // },
          // {
          //   value: 2,
          //   label: "超市",
          // },
          // {
          //   value: 3,
          //   label: "面食",
          // },
          // {
          //   value: 4,
          //   label: "中仓休闲食品",
          // },
          // {
          //   value: 5,
          //   label: "中仓干果",
          // },
          // {
          //   value: 6,
          //   label: "中仓炒货",
          // },
        ],
        option: [
          {
            value: -1,
            label: "全部"
          },
          {
            value: 0,
            label: "待发货"
          },
          {
            value: 1,
            label: "已发货"
          },
          {
            value: 2,
            label: "已收货"
          }
        ],
        date: [],
        d_date: [],
        acc_type: null,
        multipleSelection: []
      };
    },
    created() {
      this.getSourceDataList();
      //页面数据
      this.getData();
    },
    methods: {
      //页面数据
      getData() {
        let data = {
          limit: this.pageData.pageSize,
          page: this.pageData.page,
          code: this.search.code,
          org_code: this.organizationList.code,
          order_status:
            this.search.order_status == -1 ? "" : this.search.order_status,
          start_date: this.search.start_date,
          end_date: this.search.end_date,
          d_start_date: this.search.d_start_date,
          d_end_date: this.search.d_end_date,
          order_type: this.search.type == -1 ? "" : this.search.type,
          otype:
            this.search.otype == -1 || this.search.otype == 0
              ? 0
              : this.search.otype,
          category_code_str: this.classNameList.code,
          warehouse_code_str: this.warehouseList.code,
          hangcai_flag:
            this.search.hangcai_flag == -1 ? "" : this.search.hangcai_flag
        };
        selectOrderList(data)
          .then(res => {
            if (res.code == 0) {
              res.data.paginate.data.forEach(item => {
                switch (item.order_status) {
                  case 0:
                    item.statusMsg = "待发货";
                    break;
                  case 1:
                    item.statusMsg = "已发货";
                    break;
                  case 2:
                    item.statusMsg = "已收货";
                    break;
                }
                switch (item.type) {
                  case 1:
                    item.typeMsg = "商超订单";
                    break;
                  case 2:
                    item.typeMsg = "ERP商超订单";
                    break;
                  case 3:
                    item.typeMsg = "中仓强配订单";
                    break;
                  case 13:
                    item.typeMsg = "中仓回退订单";
                    break;
                }
              });
              this.acc_type = res.acc_type;
              this.tableData = res.data.paginate.data;
              this.pageData.page = res.data.paginate.current_page;
              this.pageData.pagesize = res.data.paginate.per_page;
              this.pageData.total = res.data.paginate.total;
            }
          })
          .catch(err => {
            console.log(err);
          });
      },
      // synchronization(scope) {
      //   let data = {
      //     order_id: scope.row.id,
      //   };
      //   synchroStockByOld(data).then((res) => {
      //     if (res.code == 0) {
      //       this.getData();
      //       this.$message({
      //         type: "success",
      //         message: res.msg,
      //       });
      //     }
      //   });
      // },
      getSourceDataList() {
        let data = {
          module: 1
        };
        getSourceData(data).then(res => {
          if (res.code == 0) {
            this.otype = res.data.source;
          }
        });
      },
      //拉取erp
      pull(scope) {
        let data = {
          pull_date: this.erpCenter.date,
          type: 2
        };
        this.$confirm("是否拉取ERP?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            pullOrderData(data)
              .then(res => {
                if (res.code == 0) {
                  this.getData();
                  this.$message({
                    type: "success",
                    message: res.msg
                  });
                }
              })
              .catch(err => {
                console.log(err);
              });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消拉取ERP"
            });
          });
      },
  
      // 机构搜索
      supplierTag(data) {
        this.organizationList = {
          name: "",
          code: ""
        };
        let arrName = [];
        let arrCode = [];
        data.forEach(res => {
          arrName.push(res.name);
          arrCode.push(res.code);
        });
        this.organizationList.name = arrName.join(",");
        this.organizationList.code = arrCode.join(",");
        console.log(this.organizationList, 11111);
      },
      classTag(data) {
        this.classNameList = {
          name: "",
          code: ""
        };
        console.log(data, 11111);
        let arrName = [];
        let arrCode = [];
        data.forEach(res => {
          arrName.push(res.name);
          arrCode.push(res.code);
        });
        this.classNameList.name = arrName.join(",");
        this.classNameList.code = arrCode.join(",");
      },
      //超级机构搜索
      organizationBtn() {
        this.organizatioDialog = {
          centerDialogVisible: true
        };
      },
      //超级类别搜索
      classBtn() {
        this.classdialog = {
          centerDialogVisible: true
        };
      },
      //超级仓库搜索
      warehouseBtn() {
        this.warehouseselect = {
          centerDialogVisible: true
        };
      },
      warehouseTag(data) {
        this.warehouseList = {
          name: "",
          code: ""
        };
        console.log(data, 11111);
        let arrName = [];
        let arrCode = [];
        data.forEach(res => {
          arrName.push(res.name);
          arrCode.push(res.code);
        });
        this.warehouseList.name = arrName.join(",");
        this.warehouseList.code = arrCode.join(",");
      },
      //编辑
      modification(scope) {
        if (scope.row.hangcai_flag == 1) {
          this.detailsHcDialog.centerDialogVisible = true;
          this.detailsHcDialog.id = scope.row.id;
          this.detailsHcDialog.erp_org_code = scope.row.erp_org_code;
        } else {
          this.detailsDialog.centerDialogVisible = true;
          this.detailsDialog.id = scope.row.id;
          this.detailsDialog.erp_org_code = scope.row.erp_org_code;
        }
      },
      //详情
      handleEdit(scope) {
        if (scope.row.hangcai_flag == 1) {
          this.particularsHcDialogs.centerDialogVisible = true;
          this.particularsHcDialogs.id = scope.row.id;
        } else {
          this.particularsDialogs.centerDialogVisible = true;
          this.particularsDialogs.id = scope.row.id;
        }
      },
      //审核详情
      handleinfo(scope) {
        this.supercherkinfoDialogs.centerDialogVisible = true;
        this.supercherkinfoDialogs.id = scope.row.id;
      },
      //批量发货
      completeList() {
        this.$confirm("是否确认发货?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            if (this.multipleSelection.length > 0) {
              let data = {
                idstr: this.multipleSelection.join(",")
              };
              if (this.search.hangcai_flag == 1) {
                confirmHangCaiOrder(data)
                  .then(res => {
                    if (res.code == 0) {
                      this.$message({
                        type: "success",
                        message: res.msg
                      });
                      this.getData();
                    }
                  })
                  .catch(err => {
                    console.log(err);
                  });
              } else {
                confirmOrder(data)
                  .then(res => {
                    if (res.code == 0) {
                      this.$message({
                        type: "success",
                        message: res.msg
                      });
                      this.getData();
                    }
                  })
                  .catch(err => {
                    console.log(err);
                  });
              }
            } else {
              this.$message({
                type: "info",
                message: "请勾选订单"
              });
            }
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消发货"
            });
          });
      },
      // 确认发货
      complete(scope) {
        this.$confirm("是否确认发货?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            let data = {
              idstr: scope.row.id
            };
            if (scope.row.hangcai_flag == 1) {
              confirmHangCaiOrder(data)
                .then(res => {
                  if (res.code == 0) {
                    this.$message({
                      type: "success",
                      message: res.msg
                    });
                    this.getData();
                  }
                })
                .catch(err => {
                  console.log(err);
                });
            } else {
              confirmOrder(data)
                .then(res => {
                  if (res.code == 0) {
                    this.$message({
                      type: "success",
                      message: res.msg
                    });
                    this.getData();
                  }
                })
                .catch(err => {
                  console.log(err);
                });
            }
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消发货"
            });
          });
      },
      //行采类型切换
      hangcai_flagChe() {
        this.hangcai_flagType = false;
      },
      // 本地搜索
      handleSearch() {
        if (this.date.length > 0) {
          this.search.start_date = this.date[0];
          this.search.end_date = this.date[1];
        }
        if (this.d_date.length > 0) {
          this.search.d_start_date = this.d_date[0];
          this.search.d_end_date = this.d_date[1];
        }
        this.pageData.page = 1;
        this.pageData.total = null;
        if (this.search.hangcai_flag == "0" || this.search.hangcai_flag == "1") {
          this.hangcai_flagType = true;
        } else {
          this.hangcai_flagType = false;
        }
        this.getData();
      },
      derive(sum) {
        let link = document.createElement("a");
        let order_type = this.search.type == -1 ? "" : this.search.type;
        let otype =
          this.search.otype == -1 || this.search.otype == 0
            ? 0
            : this.search.otype;
        let order_status =
          this.search.order_status == -1 ? "" : this.search.order_status;
        console.log(sum, 9999);
        if (sum == 0) {
          if (this.acc_type == 6) {
            link.href =
              this.$axios.defaults.baseURL +
              "/smkapi/Norder/exportOrderListXLSX?token=" +
              getToken() +
              "&code=" +
              this.search.code +
              "&category_code_str=" +
              this.classNameList.code +
              "&org_code=" +
              this.organizationList.code +
              "&warehouse_code_str=" +
              this.warehouseList.code +
              "&order_type=" +
              order_type +
              "&otype=" +
              otype +
              "&order_status=" +
              order_status +
              "&start_date=" +
              this.search.start_date +
              "&end_date=" +
              this.search.end_date +
              "&d_start_date=" +
              this.search.d_start_date +
              "&d_end_date=" +
              this.search.d_end_date;
            link.click();
          } else {
            this.buttomDialog.centerDialogVisible = true;
            this.buttomDialog.sum = 0;
          }
        } else if (sum == 1) {
          if (this.acc_type == 6) {
            link.href =
              this.$axios.defaults.baseURL +
              "/smkapi/Norder/exportOrderList?token=" +
              getToken() +
              "&code=" +
              this.search.code +
              "&category_code_str=" +
              this.classNameList.code +
              "&org_code=" +
              this.organizationList.code +
              "&warehouse_code_str=" +
              this.warehouseList.code +
              "&order_type=" +
              order_type +
              "&otype=" +
              otype +
              "&order_status=" +
              order_status +
              "&start_date=" +
              this.search.start_date +
              "&end_date=" +
              this.search.end_date +
              "&d_start_date=" +
              this.search.d_start_date +
              "&d_end_date=" +
              this.search.d_end_date;
            link.click();
          } else {
            this.buttomDialog.centerDialogVisible = true;
            this.buttomDialog.sum = 1;
          }
        } else if (sum == 2) {
          if (this.acc_type == 6) {
            link.href =
              this.$axios.defaults.baseURL +
              "/smkapi/Norder/exportOrgGoods?token=" +
              getToken() +
              "&code=" +
              this.search.code +
              "&category_code_str=" +
              this.classNameList.code +
              "&org_code=" +
              this.organizationList.code +
              "&warehouse_code_str=" +
              this.warehouseList.code +
              "&order_status=" +
              order_status +
              "&order_type=" +
              order_type +
              "&otype=" +
              otype +
              "&start_date=" +
              this.search.start_date +
              "&end_date=" +
              this.search.end_date +
              "&d_start_date=" +
              this.search.d_start_date +
              "&d_end_date=" +
              this.search.d_end_date;
            link.click();
          } else {
            this.buttomDialog.centerDialogVisible = true;
            this.buttomDialog.sum = 2;
          }
        } else if (sum == 3) {
          if (this.acc_type == 6) {
            link.href =
              this.$axios.defaults.baseURL +
              "/smkapi/Norder/exportGoods?token=" +
              getToken() +
              "&code=" +
              this.search.code +
              "&category_code_str=" +
              this.classNameList.code +
              "&org_code=" +
              this.organizationList.code +
              "&warehouse_code_str=" +
              this.warehouseList.code +
              "&order_status=" +
              order_status +
              "&order_type=" +
              order_type +
              "&otype=" +
              otype +
              "&start_date=" +
              this.search.start_date +
              "&end_date=" +
              this.search.end_date +
              "&d_start_date=" +
              this.search.d_start_date +
              "&d_end_date=" +
              this.search.d_end_date;
            link.click();
          } else {
            this.buttomDialog.centerDialogVisible = true;
            this.buttomDialog.sum = 3;
          }
        }
      },
      deriveBtn(sum) {
        console.log(this.search.start_date);
        let link = document.createElement("a");
        let order_type = this.search.type == -1 ? "" : this.search.type;
        let otype =
          this.search.otype == -1 || this.search.otype == 0
            ? 0
            : this.search.otype;
        let order_status =
          this.search.order_status == -1 ? "" : this.search.order_status;
        switch (this.buttomDialog.sum) {
          case 0:
            if (sum == 1) {
              link.href =
                this.$axios.defaults.baseURL +
                "/smkapi/Norder/exportOrderListXLSX?token=" +
                getToken() +
                "&code=" +
                this.search.code +
                "&category_code_str=" +
                this.classNameList.code +
                "&org_code=" +
                this.organizationList.code +
                "&warehouse_code_str=" +
                this.warehouseList.code +
                "&order_status=" +
                order_status +
                "&order_type=" +
                order_type +
                "&otype=" +
                otype +
                "&start_date=" +
                this.search.start_date +
                "&is_zc=" +
                "&end_date=" +
                this.search.end_date +
                "&d_start_date=" +
                this.search.d_start_date +
                "&d_end_date=" +
                this.search.d_end_date;
              link.click();
            } else if (sum == 2) {
              link.href =
                this.$axios.defaults.baseURL +
                "/smkapi/Norder/exportOrderListXLSX?token=" +
                getToken() +
                "&code=" +
                this.search.code +
                "&category_code_str=" +
                this.classNameList.code +
                "&org_code=" +
                this.organizationList.code +
                "&order_status=" +
                order_status +
                "&warehouse_code_str=" +
                this.warehouseList.code +
                "&order_type=" +
                order_type +
                "&otype=" +
                otype +
                "&start_date=" +
                this.search.start_date +
                "&is_zc=1" +
                "&end_date=" +
                this.search.end_date +
                "&d_start_date=" +
                this.search.d_start_date +
                "&d_end_date=" +
                this.search.d_end_date;
              link.click();
            } else if (sum == 3) {
              link.href =
                this.$axios.defaults.baseURL +
                "/smkapi/Norder/exportOrderListXLSX?token=" +
                getToken() +
                "&code=" +
                this.search.code +
                "&category_code_str=" +
                this.classNameList.code +
                "&org_code=" +
                this.organizationList.code +
                "&warehouse_code_str=" +
                this.warehouseList.code +
                "&order_status=" +
                order_status +
                "&order_type=" +
                order_type +
                "&otype=" +
                otype +
                "&start_date=" +
                this.search.start_date +
                "&is_zc=0" +
                "&end_date=" +
                this.search.end_date +
                "&d_start_date=" +
                this.search.d_start_date +
                "&d_end_date=" +
                this.search.d_end_date;
              link.click();
            }
            break;
          case 1:
            if (sum == 1) {
              link.href =
                this.$axios.defaults.baseURL +
                "/smkapi/Norder/exportOrderList?token=" +
                getToken() +
                "&code=" +
                this.search.code +
                "&category_code_str=" +
                this.classNameList.code +
                "&org_code=" +
                this.organizationList.code +
                "&warehouse_code_str=" +
                this.warehouseList.code +
                "&order_status=" +
                order_status +
                "&order_type=" +
                order_type +
                "&otype=" +
                otype +
                "&start_date=" +
                this.search.start_date +
                "&is_zc=" +
                "&end_date=" +
                this.search.end_date +
                "&d_start_date=" +
                this.search.d_start_date +
                "&d_end_date=" +
                this.search.d_end_date;
              link.click();
            } else if (sum == 2) {
              link.href =
                this.$axios.defaults.baseURL +
                "/smkapi/Norder/exportOrderList?token=" +
                getToken() +
                "&code=" +
                this.search.code +
                "&category_code_str=" +
                this.classNameList.code +
                "&org_code=" +
                this.organizationList.code +
                "&order_status=" +
                order_status +
                "&warehouse_code_str=" +
                this.warehouseList.code +
                "&order_type=" +
                order_type +
                "&otype=" +
                otype +
                "&start_date=" +
                this.search.start_date +
                "&is_zc=1" +
                "&end_date=" +
                this.search.end_date +
                "&d_start_date=" +
                this.search.d_start_date +
                "&d_end_date=" +
                this.search.d_end_date;
              link.click();
            } else if (sum == 3) {
              link.href =
                this.$axios.defaults.baseURL +
                "/smkapi/Norder/exportOrderList?token=" +
                getToken() +
                "&code=" +
                this.search.code +
                "&category_code_str=" +
                this.classNameList.code +
                "&org_code=" +
                this.organizationList.code +
                "&warehouse_code_str=" +
                this.warehouseList.code +
                "&order_status=" +
                order_status +
                "&order_type=" +
                order_type +
                "&otype=" +
                otype +
                "&start_date=" +
                this.search.start_date +
                "&is_zc=0" +
                "&end_date=" +
                this.search.end_date +
                "&d_start_date=" +
                this.search.d_start_date +
                "&d_end_date=" +
                this.search.d_end_date;
              link.click();
            }
            break;
          case 2:
            if (sum == 1) {
              link.href =
                this.$axios.defaults.baseURL +
                "/smkapi/Norder/exportOrgGoods?token=" +
                getToken() +
                "&code=" +
                this.search.code +
                "&category_code_str=" +
                this.classNameList.code +
                "&org_code=" +
                this.organizationList.code +
                "&warehouse_code_str=" +
                this.warehouseList.code +
                "&order_status=" +
                order_status +
                "&order_type=" +
                order_type +
                "&otype=" +
                otype +
                "&start_date=" +
                this.search.start_date +
                "&is_zc=" +
                "&end_date=" +
                this.search.end_date +
                "&d_start_date=" +
                this.search.d_start_date +
                "&d_end_date=" +
                this.search.d_end_date;
              link.click();
            } else if (sum == 2) {
              link.href =
                this.$axios.defaults.baseURL +
                "/smkapi/Norder/exportOrgGoods?token=" +
                getToken() +
                "&code=" +
                this.search.code +
                "&category_code_str=" +
                this.classNameList.code +
                "&org_code=" +
                this.organizationList.code +
                "&warehouse_code_str=" +
                this.warehouseList.code +
                "&order_status=" +
                order_status +
                "&order_type=" +
                order_type +
                "&otype=" +
                otype +
                "&start_date=" +
                this.search.start_date +
                "&is_zc=1" +
                "&end_date=" +
                this.search.end_date +
                "&d_start_date=" +
                this.search.d_start_date +
                "&d_end_date=" +
                this.search.d_end_date;
              link.click();
            } else if (sum == 3) {
              link.href =
                this.$axios.defaults.baseURL +
                "/smkapi/Norder/exportOrgGoods?token=" +
                getToken() +
                "&code=" +
                this.search.code +
                "&category_code_str=" +
                this.classNameList.code +
                "&org_code=" +
                this.organizationList.code +
                "&warehouse_code_str=" +
                this.warehouseList.code +
                "&order_status=" +
                order_status +
                "&order_type=" +
                order_type +
                "&otype=" +
                otype +
                "&start_date=" +
                this.search.start_date +
                "&is_zc=0" +
                "&end_date=" +
                this.search.end_date +
                "&d_start_date=" +
                this.search.d_start_date +
                "&d_end_date=" +
                this.search.d_end_date;
              link.click();
            }
            break;
          case 3:
            if (sum == 1) {
              link.href =
                this.$axios.defaults.baseURL +
                "/smkapi/Norder/exportGoods?token=" +
                getToken() +
                "&code=" +
                this.search.code +
                "&category_code_str=" +
                this.classNameList.code +
                "&org_code=" +
                this.organizationList.code +
                "&warehouse_code_str=" +
                this.warehouseList.code +
                "&order_status=" +
                order_status +
                "&order_type=" +
                order_type +
                "&otype=" +
                otype +
                "&start_date=" +
                this.search.start_date +
                "&is_zc=" +
                "&end_date=" +
                this.search.end_date +
                "&d_start_date=" +
                this.search.d_start_date +
                "&d_end_date=" +
                this.search.d_end_date;
              link.click();
            } else if (sum == 2) {
              link.href =
                this.$axios.defaults.baseURL +
                "/smkapi/Norder/exportGoods?token=" +
                getToken() +
                "&code=" +
                this.search.code +
                "&category_code_str=" +
                this.classNameList.code +
                "&org_code=" +
                this.organizationList.code +
                "&warehouse_code_str=" +
                this.warehouseList.code +
                "&order_status=" +
                order_status +
                "&order_type=" +
                order_type +
                "&otype=" +
                otype +
                "&start_date=" +
                this.search.start_date +
                "&is_zc=1" +
                "&end_date=" +
                this.search.end_date +
                "&d_start_date=" +
                this.search.d_start_date +
                "&d_end_date=" +
                this.search.d_end_date;
              link.click();
            } else if (sum == 3) {
              link.href =
                this.$axios.defaults.baseURL +
                "/smkapi/Norder/exportGoods?token=" +
                getToken() +
                "&code=" +
                this.search.code +
                "&category_code_str=" +
                this.classNameList.code +
                "&org_code=" +
                this.organizationList.code +
                "&warehouse_code_str=" +
                this.warehouseList.code +
                "&order_status=" +
                order_status +
                "&order_type=" +
                order_type +
                "&otype=" +
                otype +
                "&start_date=" +
                this.search.start_date +
                "&is_zc=0" +
                "&end_date=" +
                this.search.end_date +
                "&d_start_date=" +
                this.search.d_start_date +
                "&d_end_date=" +
                this.search.d_end_date;
              link.click();
            }
            break;
        }
      },
      //删除
      handleDelete(scope) {
        let data = {
          id: scope.row.id
        };
        console.log(scope);
        this.$confirm("是否删除该条信息?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            deleteOrder(data).then(res => {
              if (res.code == 0) {
                this.getData();
                this.$message({
                  type: "success",
                  message: res.msg || res.message
                });
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
      },
      deriveList() {
        this.$confirm("是否导出?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            let link = document.createElement("a");
            let order_type = this.search.type == -1 ? "" : this.search.type;
            let otype =
              this.search.otype == -1 || this.search.otype == 0
                ? 0
                : this.search.otype;
            let order_status =
              this.search.order_status == -1 ? "" : this.search.order_status;
            link.href =
              this.$axios.defaults.baseURL +
              "/smkapi/Norder/exportOrgGoodsNew?token=" +
              getToken() +
              "&code=" +
              this.search.code +
              "&category_code_str=" +
              this.classNameList.code +
              "&org_code=" +
              this.organizationList.code +
              "&warehouse_code_str=" +
              this.warehouseList.code +
              "&order_status=" +
              order_status +
              "&order_type=" +
              order_type +
              "&otype=" +
              otype +
              "&start_date=" +
              this.search.start_date +
              "&end_date=" +
              this.search.end_date +
              "&d_start_date=" +
              this.search.d_start_date +
              "&d_end_date=" +
              this.search.d_end_date;
            link.click();
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消导出"
            });
          });
      },
      //添加商品
      addGoods() {
        this.addDialog.centerDialogVisible = true;
      },
      //单品多店添加
      addMoreGoods() {
        this.addMoreDialog.centerDialogVisible = true;
      },
      addHcGoods() {
        this.addHcDialog.centerDialogVisible = true;
      },
      //搜索清除
      empty() {
        this.search = {
          code: "",
          order_status: "",
          start_date: "",
          end_date: "",
          d_start_date: "",
          d_end_date: "",
          type: "",
          otype: ""
        };
        this.classNameList.name = "";
        this.classNameList.code = "";
        this.date = [];
        this.d_date = [];
        this.organizationList = {
          name: "",
          code: ""
        };
        this.warehouseList = {
          name: "",
          code: ""
        };
      },
      //每页多少条
      handleCurrentChange(val) {
        this.pageData.page = 1;
        this.pageData.pageSize = val;
  
        this.getData();
      },
      //选取页数
      handleSizeChange(page) {
        this.pageData.page = page;
  
        this.getData();
      },
      //选取
      handleSelectionChange(val) {
        this.multipleSelection = [];
        let valMain = val;
        valMain.forEach(res => {
          this.multipleSelection.push(res.serial_code);
        });
      }
    }
  };
  </script>
  <style scoped>
  .top {
    position: relative;
  }
  
  .add {
    position: absolute;
    right: 0;
    top: 4px;
  }
  .pagination {
    text-align: right;
    padding: 10px;
  }
  .inp {
    margin-bottom: 5px;
    width: 300px;
  }
  </style>
  